(********************************************************************)
(*	file: 		ADSPAttention.p										*)
(*	version:	.5alpha 											*)
(* 																	*)
(* Send an out of stream message to the connection end	whose name 	*)
(* is specified by parameter1.  The message is any valid Hypercard	*)
(* message plus parameters.	 Will return an error if the connection *)
(* is not established.  Attention messages that are longer than	570	*)
(* bytes will be truncated to 570 bytes which is the max size of an	*)
(* attention message.												*)
(*																	*)
(* In:	params[1] =	name of the entity to talk to.					*)
(*		params[2] = attention message to send to that entity		*)
(*																	*)
(* ----------------------------------------------------------------	*)
(* By:		Donald Koscheka											*)
(* Date:	1-Mar-88												*)
(* 			©	Copyright 1988, Apple Computer, Inc.				*)
(*			All Rights Reserved										*)
(*																	*)
(* ----------------------------------------------------------------	*)
(*						Modification History						*)
(* ----------------------------------------------------------------	*)
(*  Date	| By	|	 				Description					*)
(* ----------------------------------------------------------------	*)
(*  1-Mar-88| DK	| file created									*)
(* 17-Mar-88| DK	| ALPHA RELEASE									*)
(* 13-May-88| DK	| generalized the DSPAttention mechanism		*)
(* ----------------------------------------------------------------	*)
(********************************************************************)

(*******************************************************************
							Build Sequence

pascal -o "{hpo}"ADSPAttention.p.o "{adsp}"ADSPAttention.p
link -m ENTRYPOINT  -rt XCMD=1306 -sn Main=ADSPAttention¶
	"{hpo}"ADSPAttention.p.o¶
	"{libraries}"Interface.o ¶
	"{plibraries}"paslib.o¶
	-o "{hp}"HyperADSPTest
		 
*******************************************************************)


{$R-}
{$S ADSPAttention}
UNIT DummyUnit;

(*******************************************************************)
INTERFACE 
(*******************************************************************)


Uses MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, HyperXCmd, AppleTalk, ADSP, adspxcmd;


Procedure EntryPoint( paramPtr : XCmdPtr );



(*******************************************************************)
IMPLEMENTATION
(*******************************************************************)


PROCEDURE ADSPAttention( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
	Begin
		ADSPAttention( paramPtr );
	End;
	
	
Procedure ADSPAttention( paramPtr : XCmdPtr );
VAR
	adsp		: ADSPPtr;
	error		: OSErr;
	eAddr		: AddrBlock;
	cn			: cbPtr;
	HSiz		: LongInt;
	
{$I XCmdGlue.inc }
{$I XCMDADSP.inc }	


BEGIN
	error := errAttention;
	adsp := ADSPPtr(RetrieveHandle( GLOBALDSPDATA ));
	IF(adsp<>NIL)AND(paramPtr^.params[1]<>NIL)AND(paramPtr^.params[2]<>NIL)THEN
		BEGIN
			{*** (1) Get the entity's address 			***}
			HLock( paramPtr^.params[1] );

			eAddr := NBPGetAddress( paramPtr^.params[1]^ );
			cn := adsp^.ends;
			
			IF LongInt( eAddr ) <> 0 THEN {*** (2) Find entity in connection list***}
				WHILE cn <> NIL DO
					IF (LongInt(cn^.adr) = LongInt( eAddr )) AND (cn^.ccb.state=sOpen) THEN	
						BEGIN
							HSiz := GetHandleSize( paramPtr^.params[2] );
							HLock(paramPtr^.params[2]);
							
							error := DSPAttention( cn, paramPtr^.params[2]^, Integer(HSiz) );
							cn^.attnBuf := NIL; {*** assume we won't allocate the handle ***}
							
							HUnLock(paramPtr^.params[2]);
							cn := NIL;
						END
					ELSE
						cn := cn^.next;
			HUnlock( Handle(paramPtr^.params[1]) );
		END;
	paramPtr^.returnValue := ErrorReturn( error );
END;


end.
